package com.fit.pages.user;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.dao.user.UserDAO;
import com.fit.entities.User;
import com.fit.pages.ErrorPage;

public class Details {

	@Property
	@Persist
	private User user;

	@Inject
	private UserDAO userDAO;

	@InjectPage
	private ErrorPage errorPage;

	public boolean isEmployeeNotNull() {
		if (user.getEmployee() != null) {
			return true;
		} else {
			return false;
		}
	}

	Object onActivate(String username) {
		errorPage.setMessage("");
		user = userDAO.findByUsername(username);

		if (user == null) {
			errorPage.setMessage("Error");
			return errorPage;
		}
		return null;
	}

}
